
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/cyUtil.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/cyEasyUi.js"></script>
<link rel="stylesheet"
      href="${pageContext.request.contextPath}/js/jquery-easyui/themes/default/easyui.css"
      type="text/css"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/jquery-easyui/themes/icon.css"
          type="text/css"/>
<script type="text/javascript">
    function addFun()
    {
        var dialog = parent.modalDialog({
            title : "添加资源",
            url : "resource/resource_form.jsp",
            buttons : [{
                text : "添加",
                handler: function(){
                    dialog.find("iframe").get(0).contentWindow.submitForm(dialog,grid,parent.$);
                }
            }]
        });
    }

    function removeFun(id)
    {
        if(!confirm("是否确认删除!")){
            return;
        }

        $.ajax({
            url:"${pageContext.request.contextPath}/resource/resource_delete",
            data:{"Tmenu.id":id},
            type:"post",
            success:function(data){
                if(data.json.success){
                    grid.treegrid('reload');
                }else{
                    $.messager.show({
                        title : "提示",
                        msg: data.json.msg
                    });
                }
            }
        });
    }

    var grid;
    $(function(){
        grid = $("#grid").treegrid({
            title : "",
            url : "${pageContext.request.contextPath}/resource/resource_treeGrid",
            idField : "id",
            treeField : "name",
            parentField : "pid",
            rownumbers : true,
            pagination : false,
            sortName : "seqID",
            sortOrder : "asc",
            columns : [[{
                width : "70",
                title : "资源编号",
                field : "id"
            },{
                width : '200',
                title : '资源名称',
                field : 'name'
            },{
                width : "100",
                title : "图标名称",
                field : "icon"
            },{
                width : "150",
                title : "资源路径",
                field : "url",
                formatter : function(value, row)
                {
                    if(value)
                    {
                        return formatString("<span title='{0}'>{1}</span>,value , value");
                    }
                }
            },{
                width : "200",
                title : "资源参数",
                field : "parameter"
            },{
                width : "50",
                title : "父级编号",
                field : "pid"
            },{
                width : "50",
                title : "序号",
                field : "seqID"
            },{
                width : "100",
                title : "备注",
                field : "memo"
            },{
                widht : "200",
                title : "操作",
                field : "operat",
                formatter : function(value,row)
                {
                    var str = "";
                    str += formatString("<button type='button' onclick=\"showFun('{0}')\">{1}</button>", row.id,"查看");
                    str += formatString("<button type='button' onclick=\"editFun('{0}')\">{1}</button>", row.id,"编辑");
                    str += formatString("<button type='button' onclick=\"removeFun('{0}')\">{1}</button>", row.id,"删除");
                    return str;
                }
            }]],
            toolbar : "#toolbar",
            onBeforeLoad : function(row, param) {
                parent.$.messager.progress({
                    text : '数据加载中....'
                });
            },
            onLoadSuccess : function(row, data) {
                parent.$.messager.progress('close');
            }
        });
    });
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
<div id="toolbar" style="display: none;">
    <table>
        <tr>
            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a></td>
            <td><div class="datagrid-btn-separator"></div></td>
            <td><a onclick="redoFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-resultset_next'">展开</a><a onclick="undoFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-resultset_previous'">折叠</a></td>
            <td><div class="datagrid-btn-separator"></div></td>
            <td><a onclick="grid.treegrid('reload');" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-arrow_refresh'">刷新</a></td>
        </tr>
    </table>
</div>
<div data-options="region:'center',fit:true,border:false">
    <table id="grid" data-options="fit:true,border:false">
    </table>
</div>
</body>
</html>
